package com.czg.designmode.prototype;

import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.Scanner;

/**
 * 正方形类
 *
 * @author chenzhigang
 */
@Slf4j
public class Square implements Shape {

    @Override
    public Object clone() {
        Square square = null;
        try {
            square = (Square) super.clone();
        } catch (CloneNotSupportedException e) {
            log.error("克隆正方形失败：" + e.getMessage(), e);
        }
        return square;
    }

    @Override
    public BigDecimal countArea() {
        System.out.println("请输入正方形的边长：");
        Scanner input = new Scanner(System.in);
        BigDecimal side = input.nextBigDecimal();
        return side.multiply(side).setScale(2, BigDecimal.ROUND_HALF_UP);
    }
}
